package com.ai.manager.edu.cms.section;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ai.common.model.Pagination;
import com.ai.dao.edu.cms.section.SectionInfoMapper;
import com.ai.model.edu.cms.section.SectionInfo;
import com.ai.model.edu.cms.section.dto.SectionInfoDTO;
import com.ai.model.edu.cms.section.vo.SectionInfoVO;

@Component
public class SectionInfoManager {

    @Resource
    private SectionInfoMapper sectionInfoMapper;
    
    /**
     * 
     * Method Name		: findSectionInfoPageByDTO<br>
     * 
     * Description		: 根据DTO查询栏目分页信息<br>
     *  
     * @param sectionInfoDTO
     * @return
     * @since
     *
     */
    public Pagination<SectionInfoVO> findSectionInfoPageByDTO(SectionInfoDTO sectionInfoDTO) {
        Pagination<SectionInfoVO> pg = new Pagination<SectionInfoVO>();
        List<SectionInfoVO> sectionInfoVOs = sectionInfoMapper.findSectionInfoPageByDTO(sectionInfoDTO);
        int count = sectionInfoMapper.countSectionInfoPageByDTO(sectionInfoDTO);
        pg.setRows(sectionInfoVOs);
        pg.setTotal(count);
        return pg;
    }

    /**
     * 
     * Method Name		: findSubSectionInfoByParentIdList<br>
     * 
     * Description		: 根据父栏目ID批量查询所有子栏目（主题）信息集合<br>
     *  
     * @param parentSectionInfoIdList
     * @return
     * @since
     *
     */
    public List<SectionInfoVO> findSubSectionInfoByParentIdList(List<Long> parentSectionIdList, Byte isDelete) {
        Map<String, Object> params = new HashMap<String, Object>(2);
        params.put("parentSectionIdList", parentSectionIdList);
        params.put("isDelete", isDelete);
        return sectionInfoMapper.findSubSectionInfoByParentIdList(params);
    }

    /**
     * 
     * Method Name		: findAllChannelList<br>
     * 
     * Description		: 查询所有一级栏目-频道列表，作为选择频道用<br>
     *  
     * @return
     * @since
     *
     */
    public List<SectionInfoVO> findAllChannelList() {
        return sectionInfoMapper.findAllChannelList();
    }

    /**
     * Description  ： 根据所属栏目查找最大的序列值<br>
     * 
     * wumc
     * @param parentSectionId
     * @return
     * @since
     *
     */
    public int findMaxSortCountByParentSectionId(Long parentSectionId) {
        Map<String, Object> params = new HashMap<String, Object>(1);
        params.put("parentSectionId", parentSectionId);
        Integer sortCount = sectionInfoMapper.findMaxSortCountByParentSectionId(params);
        if(sortCount == null) {
            return 0;
        } else {
            return sortCount;
        }
    }

    /**
     * Description  ： 新增栏目<br>
     * 
     * wumc
     * @param sectionInfo
     * @return
     * @since
     *
     */
    public int addSectionInfo(SectionInfoDTO sectionInfoDTO) {
        return sectionInfoMapper.addSectionInfo(sectionInfoDTO);
    }

    /**
     * Description  ： 更新栏目<br>
     * 
     * wumc
     * @param sectionInfo
     * @return
     * @since
     *
     */
    public int updateSectionInfo(SectionInfoDTO sectionInfoDTO) {
        return sectionInfoMapper.updateSectionInfo(sectionInfoDTO);
    }

    /**
     * Description  ： 根据ID查询栏目信息<br>
     * 
     * wumc
     * @param sectionId
     * @return
     * @since
     *
     */
    public SectionInfoVO findSectionInfoById(Long sectionId) {
        Map<String, Object> params = new HashMap<String, Object>(1);
        params.put("sectionId", sectionId);
        return sectionInfoMapper.findSectionInfoById(params);
    }

    /**
     * Description  ： 根据栏目ID，更新栏目排序序号<br>
     * 
     * wumc
     * @param sectionInfo
     * @since
     *
     */
    public void updateSectionSortById(SectionInfo sectionInfo) {
        sectionInfoMapper.updateSectionSortById(sectionInfo);
    }

    /**
     * Description  ： 启用停用栏目<br>
     * 
     * wumc
     * @param updateSectionIdList
     * @param isDelete
     * @param updateBy
     * @since
     *
     */
    public void enableSectionByIdList(List<Long> updateSectionIdList, Byte isDelete, Long updateBy) {
        Map<String, Object> params = new HashMap<String, Object>(3);
        params.put("updateSectionIdList", updateSectionIdList);
        params.put("isDelete", isDelete);
        params.put("updateBy", updateBy);
        sectionInfoMapper.enableSectionByIdList(params);
    }

    /**
     * Description	： 根据ID查询栏目信息集合<br>
     * 
     * wumc
     * @param sectionIdList
     * @return
     * @since
     *
     */
    public List<SectionInfoVO> querySectionInfoListByIds(List<Long> sectionIdList) {
        return sectionInfoMapper.querySectionInfoListByIds(sectionIdList);
    }

	public List<SectionInfoVO> sectionTreeByParentId(Long parentId) {
		 return sectionInfoMapper.sectionTreeByParentId(parentId);
	}

	public List<SectionInfoVO> validSectionNamesByDto(
			SectionInfoDTO sectionInfoDTO) {
		return sectionInfoMapper.validSectionNamesByDto(sectionInfoDTO);
	}
}
